import PDCItemsInfo from '../icons/providencraft_item.json'
import MinecraftIcons from '../icons/minecraft_items.json'

const PDCIconsMap = new Map(PDCItemsInfo.map((item) => [item.registerName, {
  ...item,
  smallIcon: `data:image/png;base64,${item.smallIcon}`,
  largeIcon: `data:image/png;base64,${item.largeIcon}`,
}]))
const MinecraftIconsMap = new Map((MinecraftIcons as typeof PDCItemsInfo).map((item) => [item.registerName, {
  ...item,
  smallIcon: `data:image/png;base64,${item.smallIcon}`,
  largeIcon: `data:image/png;base64,${item.largeIcon}`,
}]))

/**
 * 获取物品图标
 * @param id 物品 id，如果不带上前缀会自动添加 `providencraft:` 作为前缀
 * @returns 
 */
export default function (id = '') {
  if (!id.startsWith('providencraft:') && !id.startsWith('minecraft:')) {
    id = `providencraft:${id}`
  }

  const FinalIcon = PDCIconsMap.get(id) || MinecraftIconsMap.get(id)

  return FinalIcon
}